package gortepfeil;

/**
 * This class represents a 2d Point.
 * A 2d point is a coordinate which consists of two values (x,y).
 * @author Matthias Pfeil
 *
 */
public class Point 
{
	/**
	 * x and y value for a point
	 */
	private double x, y;
	
	/**
	 * Constructor for a point object
	 * @param x x-value of the point
	 * @param y y-value of the point
	 */
	public Point(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Setter for x-value
	 * @param x x-value to be set
	 */
	public void setX(double x)
	{
		this.x = x;
	}
	
	/**
	 * Setter for y-value
	 * @param y y-value to be set
	 */
	public void setY(double y)
	{
		this.y = y;
	}
	
	/**
	 * Getter for x-value
	 * @return x-value of the point
	 */
	public double getX()
	{
		return this.x;
	}
	
	/**
	 * Getter for y-value
	 * @return y-value of the point
	 */
	public double getY() 
	{
		return this.y;
	}
	
	/**
	 * Calculates the direct distance between two points
	 * @param b second point for calculation
	 * @return distance between the two points
	 */
	public double calcDistanceTo(Point b)
	{
		return Math.sqrt(Math.pow(this.getX()-b.getX(), 2) + Math.pow(this.getY()-b.getY(),2));
	}
	
	/**
	 * Checks if another point is at the same coordinates
	 * @param point to check
	 * @return true if the point is at the same coordinates, false if it is not
	 */
	public boolean isEqualToPoint(Point point)
	{
		if (this.x == point.getX() && this.y == point.getY())
		{
			return true;
		}
		else
		{
			return false;	
		}
	}
	
	/**
	 * toString method for displaying a point on the console
	 * @return Point coordinates on the console as follows: P(x/y)
	 */
	@Override
	public String toString() 
	{
		return "P("+this.getX()+"/"+this.getY()+")";
	}
}
